<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" size="xl" title="图元详情" hide-footer scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <!--begin::div-->
            <div class="m-form m-form--fit m-form--label-align-left m-form--group-seperator-dashed">
                <div class="m-portlet__body">
                    <b-card no-body>         
                        <!--
                            pills
                            card
                            vertical：靠左显示
                        -->               
                        <b-tabs pills card >
                            <b-tab title="基本属性" active>
                                <b-card-text>
                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">图元分类</label>
                                        </div>
                                        <div class="col-md-2">
                                            <el-select maxlength="20" disabled v-model="graphPelForm.graphPelCategory"
                                                placeholder="请输入">
                                                <el-option
                                                    v-for="item in [{value:'',label:'请选择'},{value:'0',label:'其它'},
                                                    {value:'1',label:'一次接线图'},{value:'2',label:'工业'},{value:'3',label:'电力'}]"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </div>
                                        <div class="col-md-1">
                                            <label class="col-form-label">节点类型</label>
                                        </div>
                                        <div class="col-md-2">
                                            <el-select maxlength="20" disabled v-model="graphPelForm.graphPelCellType"
                                                placeholder="请输入">
                                                <el-option
                                                    v-for="item in [{value:'',label:'请选择'},{value:'0',label:'svg'},
                                                    {value:'1',label:'image'},{value:'2',label:'其它'}]"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </div>
                                    </div>
                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">图元名称</label>
                                        </div>
                                        <div class="col-md-2">
                                            <input class="form-control" type="text" maxlength="255" disabled v-model="graphPelForm.title" placeholder="请输入">
                                        </div>
                                        <div class="col-md-1">
                                            <label class="col-form-label">键</label>
                                        </div>
                                        <div class="col-md-3">
                                            <input class="form-control" type="text" disabled v-model="graphPelForm.graphPelKey" placeholder="请输入">
                                        </div>
                                        <div class="col-md-1">
                                            <label class="col-form-label">类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型</label>
                                        </div>
                                        <div class="col-md-2">
                                            <el-select maxlength="20" disabled v-model="graphPelForm.graphPelType"
                                                placeholder="请输入">
                                                <el-option
                                                    v-for="item in [{value:'',label:'请选择'},{value:'1',label:'遥测'},
                                                    {value:'2',label:'遥信'},{value:'3',label:'遥脉'},{value:'4',label:'遥控'},{value:'5',label:'虚遥'},]"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </div>
                                    </div>
                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">宽&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度</label>
                                        </div>
                                        <div class="col-md-1">
                                            <el-input-number disabled v-model="graphPelForm.width" maxlength="6" style="width:100px;"
                                                controls-position="right" :min="0" :max="999999">
                                            </el-input-number>
                                        </div>
                                        <div class="col-md-1">

                                        </div>
                                        <div class="col-md-1">
                                            <label class="col-form-label">高&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度</label>
                                        </div>
                                        <div class="col-md-1">
                                            <el-input-number disabled v-model="graphPelForm.height" maxlength="6" style="width:100px;"
                                                controls-position="right" :min="0" :max="999999">
                                            </el-input-number>
                                        </div>
                                    </div>

                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态</label>
                                        </div>
                                        <div class="col-md-2">
                                            <el-select maxlength="20" disabled v-model="graphPelForm.status"
                                                placeholder="请输入">
                                                <el-option
                                                    v-for="item in [{value:'',label:'请选择'},{value:'0',label:'暂停'},
                                                    {value:'1',label:'发布'}]"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </div>
                                        <div class="col-md-1">
                                            <label class="col-form-label">排&nbsp;&nbsp;序&nbsp;号</label>
                                        </div>
                                        <div class="col-md-1">
                                            <el-input-number disabled v-model="graphPelForm.sort" maxlength="6" style="width:100px;"
                                                controls-position="right" :min="0" :max="999999">
                                            </el-input-number>
                                        </div>
                                    </div>

                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">显示标签</label>
                                        </div>
                                        <div class="col-md-2">
                                            <el-select maxlength="20" disabled v-model="graphPelForm.hideLabel"
                                                placeholder="请输入">
                                                <el-option
                                                    v-for="item in [{value:'',label:'请选择'},{value:'0',label:'是'},
                                                    {value:'1',label:'否'}]"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </div>
                                        <div class="col-md-1">
                                            <label class="col-form-label">显示标题</label>
                                        </div>
                                        <div class="col-md-2">
                                            <el-select maxlength="20" disabled v-model="graphPelForm.hideTitle"
                                                placeholder="请输入">
                                                <el-option
                                                    v-for="item in [{value:'',label:'请选择'},{value:'0',label:'是'},
                                                    {value:'1',label:'否'}]"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </div>
                                    </div>
                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">预览图标</label>
                                        </div>
                                        <div class="col-md-3"  style="display: none;">
                                            <input  class="form-control" type="file" id="file-input" accept = "image/*">
                                            <input class="form-control" disabled type="hidden" id="image" name="image" placeholder="请输入键">
                                        </div>
                                        <div class="col-md-3">
                                            <img alt="" src="" id="imgCav" width="40" height="40">
                                        </div>
                                    </div>
                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">SvgHtml</label>
                                        </div>
                                        <div class="col-md-6">
                                            <textarea class="form-control" disabled rows="10" v-model="graphPelForm.svgHtml"></textarea>
                                        </div>
                                        <div class="col-md-4">
                                            <label class="col-form-label"> 说明：仅限于SVG节点类型：<code>用于渲染设计器中节点</code>等.</label>
                                        </div>
                                    </div>
                                    <div class="form-group m-form__group row">
                                        <div class="col-md-1">
                                            <label class="col-form-label">渲染方式</label>
                                        </div>
                                        <div class="col-md-3">
                                            <el-select maxlength="20" disabled v-model="graphPelForm.renderMethod"
                                                placeholder="请输入">
                                                <el-option
                                                    v-for="item in [{value:'',label:'请选择'},{value:0,label:'按元素列表组装渲染'},
                                                    {value:1,label:'按svghtml文件渲染'}]"
                                                    :key="item.value"
                                                    :label="item.label"
                                                    :value="item.value">
                                                </el-option>
                                            </el-select>
                                        </div>
                                        <div class="col-md-4">
                                            <label class="col-form-label">说明：仅限于SVG节点类型：<code>用于渲染设计器中节点</code>等.</label>
                                        </div>
                                    </div>
                                </b-card-text>
                            </b-tab>
                            <b-tab title="节点信息" >
                                <b-card-text>
                                    <div class="form-group m-form__group row">
                                        <div class="col-md-6">
                                            <label class="col-form-label">
                                                说明：仅限于SVG节点类型：<code>用于渲染设计器中节点</code>等.
                                            </label>
                                        </div>
                                    </div>  
                                    <div v-for="(item, index) in graphPelForm.graphPelElements" :key="index" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed">  
                                        <div class="form-group m-form__group row">
                                            <label class="col-md-1 col-form-label">
                                                序号.{{ index+1 }}
                                            </label>
                                        </div>
                                        <div class="form-group m-form__group row">
                                            <label class="col-md-1 col-form-label">类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型</label>
                                            <div class="col-md-2">
                                                <el-select maxlength="20" v-model="item.category" disabled placeholder="请输入">
                                                    <el-option
                                                        v-for="item in [{value:'',label:'请选择'},{value:'path',label:'path'},
                                                        {value:'ellipse',label:'ellipse'},{value:'circle',label:'circle'},
                                                        {value:'rect',label:'rect'},{value:'line',label:'line'},
                                                        {value:'polygon',label:'polygon'},{value:'polyline',label:'polyline'},
                                                        {value:'text',label:'text'}]"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value">
                                                    </el-option>
                                                </el-select>
                                            </div> 
                                            <label class="col-md-1 col-form-label">线框宽度</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.stroke_width" maxlength="6" disabled style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>
                                            <label class="col-md-2 col-form-label">排&nbsp;序&nbsp;&nbsp;号</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.sort" maxlength="6" disabled style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>                                           
                                        </div>                                      
                                        <div class="form-group m-form__group row">                                            
                                            <label class="col-md-1 col-form-label">填充颜色</label>
                                            <div class="col-md-2">
                                                <el-color-picker v-model="item.fills" disabled></el-color-picker>
                                            </div>  
                                        </div>
                                        <div class="form-group m-form__group row">         
                                            <label class="col-md-1 col-form-label">线条颜色</label>
                                            <div class="col-md-2">
                                                <el-color-picker v-model="item.stock" disabled></el-color-picker>
                                            </div>
                                        </div>
                                        <div class="form-group m-form__group row">
                                            <label class="col-md-1 col-form-label">透&nbsp;明&nbsp;&nbsp;度</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.graphPelElementOpacity" disabled maxlength="6" style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>
                                            <label class="col-md-2 col-form-label">线条透明度</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.stroke_opacity" disabled maxlength="6" style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>
                                            <label class="col-md-2 col-form-label">填充透明度</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.fill_opacity" disabled maxlength="6" style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>
                                        </div>
                                        <div class="form-group m-form__group row">                                            
                                            <label class="col-md-1 col-form-label">cx</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.graphPelElementCx" disabled maxlength="6" style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>
                                            <label class="col-md-2 col-form-label">cy</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.graphPelElementCy" disabled maxlength="6" style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>
                                            <label class="col-md-2 col-form-label">r</label>
                                            <div class="col-md-1">
                                                <el-input-number v-model="item.graphPelElementR" disabled maxlength="6" style="width:100px;"
                                                    controls-position="right" :min="0" :max="999999">
                                                </el-input-number>
                                            </div>
                                        </div>
                                        <div class="form-group m-form__group row">
                                            <label class="col-md-1 col-form-label">代&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码</label>
                                            <div class="col-md-6">
                                                <textarea class="form-control" disabled style="overflow: hidden; overflow-wrap: break-word; resize: none; height: 73px;" rows="1" v-model="item.attrs"  placeholder="请输入"/>
                                            </div>
                                        </div>   
                                    </div>                           
                                </b-card-text>
                            </b-tab>
                        </b-tabs>                        
                    </b-card>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
           
        </template>
    </b-modal>        
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js"; 
import { handleNotify,handleAlert,handleConfirm,showWating,closeWating} from "@/core/util/jehcUtil.js";
export default {
    data(){
        return {    
            graphPelForm:{
                id:"",
                graphPelCategory: "",
                graphPelCellType:"",
                title:"",
                graphPelKey:"",
                graphPelType:"",
                width:16,
                height:16,
                status:"",
                hideLabel:"",
                hideTitle:"",
                sort:0,
                renderMethod:"",
                graphPelElements:[],
            }
        }
    },
    components: {
        
    },
    watch: {
        "graphPelForm.graphPelElements.strokeColor":{//监听字段变化
            handler:function(newVal,old){
                if(newVal){
                    console.log("newVal",newVal);
                }
            }
        },
    },
    mounted() {
        
    },
    methods: {
        
        showModal(id) {
            this.restForm();
            this.$refs['my-modal'].show();
            this.getDetail(id);
        },
        getDetail(id){
            apiUtil.get(process.env.VUE_APP_MONITOR_API+"/graphPel/get/"+id).then(({ data }) => {
                this.graphPelForm = data.data;
            });
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        addGraphPelElementItems(){
            let item = {
                category: '',
                fills:"#fff",
                fillColor:"#fff",
                stock:"#FF0000",
                strokeColor:"#FF0000",
                stroke_width:0,
                graphPelElementOpacity:0,
                fill_opacity:0,
                stroke_opacity:0,
                sort:0,
                graphPelElementCx:0,
                graphPelElementCy:0,
                graphPelElementR:0,
                attrs:"",
            };
            this.graphPelForm.graphPelElements.push(item);
        },
        restForm(){
            //重置
            Object.assign(this.$data.graphPelForm, this.$options.data().graphPelForm);
        },
        deleteRow(index){
            this.$bvModal.msgBoxConfirm('确定要删除该项?', {
                title: '提示',
                size: 'sm',
                buttonSize: 'sm',
                okVariant: 'success',
                okTitle: '确定',
                cancelTitle: '取消',
                headerClass: 'p-2 border-bottom-0',
                footerClass: 'p-2 border-top-0',
                hideHeaderClose: false,
                centered: true
            }).then(value => {
                if(value){           
                    this.graphPelForm.graphPelElements.splice(index, 1)
                    this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    })
                }                
            }).catch(err => {               
            }) 
        },
   }
}
</script>